import AutoChart from '@/components/Echarts/AutoChart';
// @ts-ignore
import { medicinePrescription } from '@/services/api';
import { BorderBox1 } from '@jiaminghi/data-view-react';
import { useEffect } from 'react';
import { useImmer } from 'use-immer';
import './Chart4.less';

const ColumnCharts: React.FC = () => {
  const [options, setOptions] = useImmer({
    grid: {
      top: '4%',
      left: '7%',
      right: '4%',
      bottom: '8%',
      containLabel: true,
    },
    tooltip: {
      trigger: 'item',
      axisPointer: {
        type: 'cross',
      },
    },
    xAxis: {
      type: 'category',
      data: [],
    },
    yAxis: {
      type: 'value',
    },
    series: [
      {
        data: [],
        type: 'line',
        smooth: true,
        stack: 'Total',
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0.75,
                color: '#c1fafd',
              },
              {
                offset: 1,
                color: '#fff',
              },
            ],
          },
        },
      },
    ],
  });

  useEffect(() => {
    medicinePrescription().then((res) => {
      setOptions((draft) => {
        draft.xAxis.data = res.data.map((i) => i.name);
        draft.series[0].data = res.data.map((i) => i.value);
      });
    });
  }, []);
  return (
    <>
      <div className="'marginb-10">
        <BorderBox1 color={['#396993', '#396993']}>
          <div className="echart_title">
            <div>中药药方统计</div>
          </div>
          <div className="chart4_height padding-5">
            <AutoChart option={options as any}></AutoChart>
          </div>
        </BorderBox1>
      </div>
    </>
  );
};
export default ColumnCharts;
